package org.ilda.func.utility;

import java.util.ArrayList;
import java.util.List;

public class StringUtility {
	
	/**
	 * 截取字符串
	 * @param content  文本内容
	 * @param beginStr 开始字符
	 * @param endStr   结束字符
	 * @return
	 */
	public static String getSubString(String content, String beginStr, String endStr){
		
		int beginIdx = content.indexOf(beginStr);
		int endIdx = content.indexOf(endStr);
		
		if(beginIdx == -1){
			beginIdx = 0;
		}else{
			beginIdx = beginStr.length() + beginIdx;
		}
		if(endIdx == -1){
			endIdx = 0;
		}
		
		return content.substring(beginIdx, endIdx);
	}
	
	public static List<String> getSubStrArray(String content, String beginStr, String endStr){
		
		String url = null;
		
		ArrayList<String> list = new ArrayList<String>();
		
		int startIdx = 0;
		int endIdx = 0;
		
		
		while(endIdx < content.length()){
			startIdx = content.indexOf(beginStr);
			if(startIdx != -1){
				startIdx = beginStr.length() + startIdx;
			}else{
				return list;
			}
			endIdx = content.indexOf(endStr, startIdx);
			if(endIdx == -1){
			   return list;
			}
			
			url = content.substring(startIdx, endIdx);
			list.add(url);
			content = content.substring(endIdx + endStr.length(), content.length());
			
		}
		
		
		return list;
	}
	

	

}
